home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / timer.iqc / TIMER.INC
Encoding:
Text File  |  1985-06-29  |  1.4 KB  |  58 lines

  1. {@@@@@ TIMER routine by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  2. {   To use it, just put a "timer(on)" where you want to start timing and
  3.     a "timer(off)" at the end.  The time (in seconds, "accurate" to the
  4.     1/100 of a second) resides in the real variable "time".
  5.  
  6.     The timer routine itself takes about 4 milliseconds, so for serious
  7.     timing, you probably want to time 1000 or 10000 repetitions of the
  8.     event.  A typical scenario:
  9.  
  10.         write('1000 repetitions of <whatever> takes ');
  11.         timer(on);
  12.         for N := 1 to 1000 do
  13.           <whatever>;
  14.         timer(off);
  15.         writeLn(time:1:2);
  16.  
  17. }
  18. type
  19.   OnOrOff = (On,Off);
  20. var
  21.   start, time : real;
  22. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  23. procedure timer(O : OnOrOff);
  24. type
  25.   regpack = record
  26.               ax,bx,cx,dx,bp,si,di,ds,es,flags: integer;
  27.             end;
  28.  
  29. var
  30.   recpack          : regpack;
  31.   hour,min,sec,hun : integer;
  32.  
  33. begin
  34.   with recpack do
  35.   begin
  36.     ax := $2C shl 8;
  37.   end;
  38.   intr($21,recpack);                     {call interrupt}
  39.   with recpack do
  40.   begin
  41.     hour := cx shr 8;
  42.     min  := cx and $FF;
  43.     sec  := dx shr 8;
  44.     hun  := dx and $FF;
  45.   end;
  46.   if O = On then
  47.     begin
  48.       start := hour * 3600 + min * 60 + sec + hun/100;
  49.       time := 0;
  50.     end
  51.   else
  52.     begin
  53.       time := hour * 3600 + min * 60 + sec + hun/100 - start;
  54.       start := 0;
  55.     end;
  56. end;
  57.  
  58.